<template>
    <div class="index_container">
    <el-container>
      <el-header>
        <router-link to="/ShowCar">查看购物车</router-link>
      </el-header>
      <el-main>
         <el-row>
            <el-col :span="6" v-for="(book,index) in booksList" :key="book.book_id"  :offset="index==0?0:0" >
                <el-card :body-style="{ padding: '0px'}" style="margin-left: 10px; margin-top: 20px;">
                <img :src="require('@/assets/images/books/'+book.book_image)" class="image">
                <div class="bottom">
                  <div style="display: flex;">
                      <div class="book_desc" >
                        <div>
                          <el-tooltip class="item" effect="dark" :content="book.book_name" placement="top-start">
                            <!-- <router-link class="normal" :to="'/bookDesc/'+book.book_id">书名:{{ subBookName(book.book_name) }}</router-link> -->
                            <router-link class="normal" :to="{path:'bookDesc',query:{'book_id':book.book_id}}">书名:{{ subBookName(book.book_name) }}</router-link>
                            <!-- <span>书名:{{ subBookName(book.book_name)}}</span> -->
                          </el-tooltip>
                        </div>
                        <div><span>单价:{{book.book_price}}￥</span></div>
                      </div>
                      
                      <div class="book_car" >
                        <i style="color: orange;font-size:40px;" class=el-icon-shopping-cart-full></i>
                      </div>
                  </div>    
                  <div class="button_inputnumber" style="display: flex;">
                    <div style="margin-top: 5px;"><el-input-number size="small" v-model="num" :min="1"></el-input-number></div>                       
                    <div><el-button type="warning" @click="addCar"  plain>加入购物车</el-button></div>
                  </div>
                </div>
                </el-card>
            </el-col>
        </el-row>  
      </el-main>
      
      <el-footer>Footer</el-footer>
    </el-container>
    </div>
</template>
<script>
import BookDesc from './BookDesc.vue';
export default {

    data(){
        return{
            booksList:[],//商品数组
            num:1,//购买数量
        }
    },
    methods: {
      addCar(){
        BookDesc.methods.addCar;
      },
        /**
         * 获得商品信息
         */
       queryBooks(){
        this.$axios
                .get("book/queryBooks")
                .then(response=>{
                    this.booksList =response.data;
                })
                .catch(err=>{
                    alert(err)
                })
       },
       /**
        * 截取书名，要求书名必须小于10
        * @param {} bookName 
        */
       subBookName(bookName){
        if(bookName.length>=10){
          bookName=bookName.substring(0,10)+"..."; 
        }
        return bookName;
       }
    },
    created(){
        this.queryBooks();
    }
}
</script>
<style scoped>
.index_container{
    margin: 0px auto;
    width: 80%;

}
 .el-header, .el-footer {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
  }
  .el-main {
    background-color: #E9EEF3;
    color: #333;
  }
  
  .book_desc{
    font-size: 13px;
    width:70%;
  }

  .book_car{
    width:30%;
    margin-top: 5px;
  }
  .book_desc div{
    margin-left: 10px;
    margin-top: 10px;
  }
  .button_inputnumber div{
   margin: auto;
  }
  .bottom {
    height: 100px;
    margin-top: 13px;
    line-height: 15px;
  }
  .image {
    height: 300px;
    width: 100%;
    display: block;
  }
.normal{
  display: block;
  color: black;
  text-decoration: none;
}

.normal:hover{
  color: grey;
}
.normal:active{
  color: black;
}


  
</style>